<?php

namespace app\admin\service\pay;

use app\admin\model\pay\BoxRechargePaymentAccount;
use app\admin\model\pay\BoxRechargePayType;
use app\admin\service\BaseService;

class BoxRechargePaymentAccountService extends BaseService
{
    public function __construct()
    {
        $this->model = new BoxRechargePaymentAccount();
    }
    /**
     * Desc : getList
     * User : Steven
     * Date : 2024-05-28 14:00
     * @return array
     */
    public function getList(): array
    {
        $params = request()->param();
        $page = $params['page'] ?? 1;
        $limit = $params['limit'] ?? 15;
        $where  = [];
        if (!empty($params['company'])) {
            $where[] = ['company', 'like', '%'.$params['company'].'%'];
        }
        $where[] = ['mark', '=', 1];
        $this->model = $this->model->where($where);
        $count = $this->model->count();
        $arr = $this->model->page($page,$limit)->select();
        foreach ($arr as $key=>&$val){
            $result = [];
            $res = json_decode($val['params'],true);

            foreach ($res as $k => $v) {
                // 创建新数组并添加到转换后的数组中
                $result[] = array('item' => $k, 'value' => $v);
            }
            $val['params_list'] = $result;
        }
        // halt($arr);
       
        return [
            'code' => 0,
            'msg' => 'success',
            'count' => $count,
            'data' => $arr
        ];
    }

    public function edit()
    {
        $params = request()->param();


        $result = [];
        foreach ($params['params'] as $key=>$val){
            $result[$val['item']] = $val['value'];
        }
        if (!empty($result)) {
            $params['params'] = json_encode($result);
        }
        return parent::NewEdit($params,false,true); // TODO: Change the autogenerated stub
    }
}